﻿//数据加载
function loadTip(tips, icon, tm) {
    return layer.msg(tips, { icon: icon, time: tm, shade: [0.3, '#000'] });
}
//错误提示
function Tips(tips, objId) {
    layer.tips(tips, "#" + objId, {
        tips: [2, 'red'],
        time: 1000
    });
}
/*时间格式化*/
function ChangeDateFormat(jsondate, tag) {
    jsondate = jsondate.replace("/Date(", "").replace(")/", "");
    if (jsondate.indexOf("+") > 0) {
        jsondate = jsondate.substring(0, jsondate.indexOf("+"));
    }
    else if (jsondate.indexOf("-") > 0) {
        jsondate = jsondate.substring(0, jsondate.indexOf("-"));
    }

    var date = new Date(parseInt(jsondate, 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var result = date.getFullYear() + "年" + month + "月" + currentDate + "日";
    if (tag == undefined) {
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var m = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        result += " " + hours + "：" + m;
    }
    return result;
}
//初始化时间控件
function initDate(st, ed, fm) {
    var start = {
        elem: '#' + st,
        format: fm,
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas;
            end.start = datas
        }
    };
    var end = {
        elem: '#' + ed,
        format: fm,
        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas;
        }
    };
    laydate(start);
    laydate(end);
}
//初始化单个时间
function initSingleDate(id, fm) {
    var start = {
        elem: '#' + id,
        format: fm,
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas;
            end.start = datas
        }
    };
    laydate(start);
}
function fmoney(s, n) {
    n = n > 0 && n <= 20 ? n : 2;
    s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
    var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
    t = "";
    for (i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
    }
    return t.split("").reverse().join("") + "." + r;
}